<?
class Log extends Zend_Log{
    
    protected $_user = null;
    
    public function setUser($user)
    {
        $this->_user = $user;
    }
	
    public function __construct(Zend_Log_Writer_Abstract $writer = null){
            parent::__construct($writer);
    }
        
	
    public function log($message, $priority = Zend_Log::INFO, $extras = null){
        $user_id = 0;
        $user_name = 'Гость';
        if ($this->_user) {
            $user_id = $this->_user->getId();
            $user_name = $this->_user->getName() . ' ' . $this->_user->getSurname();
        }
        $this->setEventItem('user_id', $user_id);
        $this->setEventItem('user_name', $user_name);
        $position = strpos($message, ':');
        $action = substr($message, 0, $position);
        $message = substr($message, $position+1);
        $this->setEventItem('id', '');
        $this->setEventItem('action', $action);
        $this->setEventItem('timestamp', date('Y-m-d H:i:s'));
        parent::log(trim($message), $priority, $extras);
    }

    /**
        * Возвращает список логов
        */
    public function getLog(){

            $db = LogPeer::getInstance();

            $select = $db->select()->order('id DESC')->limit(50);
            return $db->fetchAll($select)->toArray();
    }

    public function array_render($array){
            $r = null;
            ob_start();
                    print_r($array);
            $r = ob_get_contents(); ob_end_clean();
            return $r;
    }
}